package com.jlz.actions.login;

import org.apache.struts2.convention.annotation.Standard;
import org.springframework.beans.factory.annotation.Autowired;

import com.jlz.beans.user.LinkBean;
import com.jlz.beans.user.UserBean;
import com.jlz.managers.user.Links;
import com.jlz.managers.user.Users;

@Standard
public class UserAction extends LoginBase{
	
	@Autowired Users users;
	@Autowired Links links;
	public String execute(){
		if(!validate()) return "login";
		//
		UserBean user = null;
		LinkBean link = links.find(usercode);
		if(link != null){
			switch( Links.State.of(link.getState())){
			case NEW:{
				client.putError("您的账号还未激活,进入你常用的邮箱激活");
				return "global_user_renotice";
			}
			case LOCKED: break;
			default:
				if(link.getPassword().equals(password)){
					user = users.get(link.getUserId());
				}
			}
		}
		//
		if(user == null){
			client.putError("账号或密码错误");
			return "login";
		}
		client.setSession("currentlink", link);
		client.setUser(user); 
		return "global_home_user";
	}

}
